
  <template>
  <div class="bf-commont-template">
    <!--<div style="padding: 0 16px ;">
        <h3>人才库/黑名单</h3>
      </div>-->
    <div class="clearfix bf-top-button">
      <div class="float-l">
        <el-button @click="showAdd" type="primary">添加人才</el-button>
      </div>
      <div class="float-r">
        <div class="float-l">
          <el-input placeholder="请输入姓名搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch"></el-input>
        </div>
        <div class="float-l padding-l">
          <el-button @click="showSearch" type="primary">高级筛选</el-button>
        </div>
      </div>
    </div>
    <el-tabs v-model="activeName" @tab-click="handleClick" class="margin-l margin-r">
      <el-tab-pane :label="'人才库'+ tabs.waitVett" name="resume">
        <bf-table :data="userData" :setting="resumeListSetting" :rowAction="resumeAction" @editSubmit="resumeEditSubmit" @pageChange="pageChange" ref="table"></bf-table>
      </el-tab-pane>
      <el-tab-pane :label="'淘汰库'+ tabs.vetted" name="eliminate">
        <bf-table :data="userData" :setting="eliminateListSetting" :rowAction="eliminateAction" @editSubmit="eliminateEditSubmit" @pageChange="pageChange" ref="table"></bf-table>
      </el-tab-pane>
    </el-tabs>

    <!-- 添加 -->
    <bf-table-add :width="800" :rowNum="2" :editForm='resumeDetailSetting' :title="'添加'" ref='resumeRef' @formSubmit='addResumeSubmit' :editRules="addRules"></bf-table-add>
    <!--高级搜索 -->
    <bf-table-search  :editForm='resumeDetailSetting' :title="'高级搜索'" ref='searchRosterRef' @formSubmit='searchRosterSubmit'></bf-table-search>
    <!-- 编辑 -->
    <bf-table-edit  :width="800"  :rowNum="2"  :editForm='resumeDetailSetting' :title="'人才库编辑'" ref='resumeDetailRosterRef' @formSubmit='resumeDetailRosterSubmit' :editRules="addRules"></bf-table-edit>
    <!--详情-->
    <bf-table-detail :width="800"  :rowNum="2"  ref="resumeDetail" :title="'详情'" :editForm="resumeDetailSetting"></bf-table-detail>
    <!-- 淘汰库编辑 -->
    <bf-table-edit :width="800"  :rowNum="2" :editForm='eliminateDetailSetting' :title="'淘汰库编辑'" ref='eliminateDetailRosterRef' @formSubmit='eliminateDetailRosterSubmit' :editRules="addRules"></bf-table-edit>
    <!-- 添加到候选人 -->
    <bf-table-edit :editForm='addEliminateSetting' :title="'添加候选人'" ref='addResumeRef' @formSubmit='addWriteSubmit' :editRules="addEliminaterRules"></bf-table-edit>

    <!-- 添加到候选人-->
    <bf-table-edit :editForm='addEliminateSetting' :title="'添加候选人'" ref='addEliminaterRef' @formSubmit='addEliminateSubmit' :editRules="addEliminaterRules"></bf-table-edit>

  </div>
</template>

<script>
// import request from '@/utils/request'
import { resumeListSetting, resumeDetailSetting, eliminateListSetting, eliminateDetailSetting, addEliminateSetting } from './table.setting.js'
import { deleteEliminate, getRequireList, getDetail, deleteResume, getEliminateList, findEliminateCount, findResumelibCount, goToInterviewerEliminate, getEliminateDetatil, addResume, updateResume, addEliminate, goToInterviewer } from './api.js'
export default {
  data() {
    return {
      searchData: '',
      userData: {
      },
      statusData: {},
      tabs: {
        waitVett: 0,
        vetted: 0
      },
      activeName: 'resume',
      resumeAction: [
        {
          label: '查看',
          click: (item) => {
            this.findDetailById(item.scope.row.id, this.$refs.resumeDetail.show)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.findDetailById(item.scope.row.id, this.$refs.resumeDetailRosterRef.show)
          }
        },
        {
          label: '添加到候选人',
          click: (item) => {
            this.findDetailById(item.scope.row.id, this.$refs.addResumeRef.show)

            // this.$refs.table.showDelete(item.scope)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.delResume(item.scope.row.id)
          }
        }
      ],

      eliminateAction: [
        {
          label: '移动到候选人',
          click: (item) => {
            this.findEliminateDetailById(item.scope.row.id, this.$refs.addEliminaterRef.show)
            // this.$refs.eliminateDetailRosterRef.show(item.scope)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            this.$refs.eliminateDetailRosterRef.show(item.scope)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table.showDelete(item)
          }
        }
      ],
      resumeListSetting: resumeListSetting,
      resumeDetailSetting: resumeDetailSetting,
      eliminateListSetting: eliminateListSetting,
      eliminateDetailSetting: eliminateDetailSetting,
      addEliminateSetting: addEliminateSetting,

      addEliminaterRules: {
        reqId: [
          { required: true, message: '请选择需求', trigger: 'blur' }
        ],
        recruitmentChannel: [
          { required: true, message: '请选择招聘渠道', trigger: 'blur' }
        ]
      },
      addRules: {
        reqId: [
          { required: true, message: '请选择需求', trigger: 'blur' }
        ],
        intvName: [
          { required: true, message: '请输入姓名', trigger: 'blur' },
          { min: 2, max: 20, message: '长度在 2 到 20个字符', trigger: 'blur' }
        ],
        sex: [
          { required: true, message: '请选择性别', trigger: 'blur' }
        ],
        age: [
          { required: true, message: '请输入年龄', trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: '请输入手机号', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' }
        ],
        education: [
          { required: true, message: '请输入学历', trigger: 'blur' }
        ],
        lastCompany: [
          { required: true, message: '请输入最后工作公司', trigger: 'blur' },
          { min: 1, max: 100, message: '长度在 1 到 100个字符', trigger: 'blur' }
        ],
        graduationSchool: [
          { required: true, message: '请输入毕业学校', trigger: 'blur' },
          { min: 2, max: 50, message: '长度在 2 到 50个字符', trigger: 'blur' }
        ],
        workLife: [
          { min: 1, max: 2, message: '长度在 1 到 2个字符', trigger: 'blur' }
        ],
        reasion: [
          { min: 1, max: 1000, message: '长度在 1 到 1000个字符', trigger: 'blur' }
        ]
      },
      searchParams: { // 搜索条件
        page: 1
      }
    }
  },
  mounted: function() {
    this.searchList()
    this.getTabs()
  },
  methods: {
    addResumeSubmit(form) { // 添加人才库
      addResume(form).then((response) => { // 停止招聘
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.resumeRef.hiden()
          this.searchList()
          this.getTabs()
        }
      })
    },
    searchRosterSubmit(form) { // 人才库高级搜索
      this.searchParams.education = form.education
      this.searchParams.reqId = form.reqId
      this.searchParams.workLife = form.workLife
      this.searchList()
    },
    resumeDetailRosterSubmit(form) { // 人才库编辑提交
      updateResume(form).then((response) => { // 停止招聘
        if (response.success) {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.$refs.resumeDetailRosterRef.hiden()
          this.searchList()
        }
      })
    },
    delResume(id) { // 删除人才库
      deleteResume(id).then((response) => {
        if (response.success) {
          this.searchList()
          this.getTabs()
          this.$message({
            message: '删除成功',
            type: 'success'
          })
        }
      })
    },


    addWriteSubmit(params) { // 移动到候选人 人才库
      goToInterviewer(params).then((response) => {
        if (response.success) {
          this.searchList()
          this.getTabs()
          this.$refs.addResumeRef.hiden()
          this.$message({
            message: '修改成功',
            type: 'success'
          })
        }

      })
    },

    addEliminateSubmit(params) { // 移动到候选人 淘汰库
      goToInterviewerEliminate(params).then((response) => {
        if (response.success) {
          this.searchList()
          this.getTabs()
          this.$refs.addEliminaterRef.hiden()
          this.$message({
            message: '修改成功',
            type: 'success'
          })
        }

      })
    },

    eliminateDetailRosterSubmit(form) { // 淘汰库的编辑
      addEliminate(form).then((response) => { // 停止招聘
        if (response.success) {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.$refs.table.hidenForm()
          this.$refs.eliminateDetailRosterRef.hiden()
          this.searchList()
        }
      })
    },
    findDetailById(id, showCall) { // 详情人才库
      getDetail(id).then((response) => {
        showCall(response.data)
      })
    },

    findEliminateDetailById(id, showCall) { // 详情淘汰库详情
      getEliminateDetatil(id).then((response) => {
        response.data.reqId = response.data.reqId + ''
        showCall(response.data)
      })
    },


    getTabs(forms) {
      this.tabs.waitVett = 0
      this.tabs.vetted = 0
      findEliminateCount(forms).then((request) => {
        this.statusData = request.data
        this.tabs.vetted = request.data
      })
      findResumelibCount(forms).then((request) => {
        this.statusData = request.data
        this.tabs.waitVett = request.data
      })
    },
    searchList() {
      const pageParams = this.searchParams
      if (this.activeName === 'resume') {
        getRequireList(pageParams).then((response) => {
          if (response.success) {
            this.$refs.searchRosterRef.hidden()
            this.userData = response
          }
        })
      }
      if (this.activeName === 'eliminate') {
        getEliminateList(pageParams).then((response) => {
          if (response.success) {
            this.$refs.searchRosterRef.hidden()
            this.userData = response
          }
        })
      }
    },
    resumeEditSubmit(params, formType, formList){
      if (formType === 'delete') {
        const id = params.row.id
        this.delResume(id)
      }
    },
    eliminateEditSubmit(params, formType, formList) {
      if (formType === 'delete') {
        const id = params.row.id
        deleteEliminate(id).then((Response) => {
          this.searchList()
          this.getTabs()
        })
      }
    },
    pageChange(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
    },
    showSearch() {
      this.$refs.searchRosterRef.show()
    },
    showAdd() {
      this.$refs.resumeRef.show()
    },
    quickSearch() {
      this.searchParams.intvName = this.searchData
      this.searchList()
    },
    handleClick(tab, event) {
      this.searchParams.page = 1
      this.searchList()
    }
  }
}
</script>

<style scoped>

</style>
